package com.sixkey.aspect;

/**
 * ClassName: MyEventListener
 * Package: com.sixkey.aspect
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/9/10 - 0:21
 * @Version: v1.0
 */

import com.sixkey.entity.Log;
import com.sixkey.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 事件监听者
 */
@Slf4j
@Component
public class MyEventListener {

    @Autowired
    private LogService logService;

    @Async("asyncExecutor") //开启线程池异步
    @EventListener //开启监听
    public void saveLog(Log operLog){
        //将用户操作的日志保存到数据库中
        logService.save(operLog);
        log.info("用户操作的日志记录成功保存到数据库中------");
    }
}
